home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTPtrHashMultiSet<T,H,EQ> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/tphasht.h> RWTPtrHashMultiSet<T,H,EQ> hmset; PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!! IIIIffff yyyyoooouuuu hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd hhhheeeerrrreeee.... OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ffffoooorrrr RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhTTTTaaaabbbblllleeee described in Appendix A. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn This class maintains a pointer-based collection of values, which are stored according to a hash object of type HHHH. Class TTTT is the type pointed to by the items in the collection. HHHH must provide a hash function on elements of type TTTT via a public member unsigned long operator()(const T& x) Objects within the collection will be grouped together based on an equality object of type EEEEQQQQ. EEEEQQQQ must ensure this grouping via public member bool operator()(const T& x, const T& y) which should return ttttrrrruuuueeee if xxxx and yyyy are equivalent, ffffaaaallllsssseeee otherwise. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> may contain multiple items that compare equal to each other. (RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> will not accept an item that compares equal to an item already in the collection.) PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Isomorphic EEEExxxxaaaammmmpppplllleeeessss // PPPPaaaaggggeeee 1111 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) // tphasht.cpp // #include <rw/tphasht.h> #include <rw/cstring.h> #include <iostream.h> struct silly_hash{ unsigned long operator()(RWCString x) const { return x.length() * (long)x(0); } }; main(){ RWTPtrHashMultiSet<RWCString,silly_hash,equal_to<RWCString> > set1; RWTPtrHashMultiSet<RWCString,silly_hash,equal_to<RWCString> > set2; set1.insert(new RWCString("one")); set1.insert(new RWCString("two")); set1.insert(new RWCString("three")); set1.insert(new RWCString("one")); // OK: duplicates allowd cout << set1.entries() << endl; // Prints "4" set2 = set1; cout << ((set1.isEquivalent(set2)) ? "TRUE" : "FALSE") << endl; // Prints "TRUE" set2.difference(set1); set1.clearAndDestroy(); cout << set1.entries() << endl; // Prints "0" cout << set2.entries() << endl; // Prints "0" return 0; } RRRReeeellllaaaatttteeeedddd CCCCllllaaaasssssssseeeessss Class RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> offers the same interface to a pointer-based collection that will not accept multiple items that compare equal to each other. Class rrrrwwww____hhhhaaaasssshhhhmmmmuuuullllttttiiiisssseeeetttt<<<<TTTT****,rrrrwwww____ddddeeeerrrreeeeffff____hhhhaaaasssshhhh<<<<HHHH,,,,TTTT>>>>,,,,rrrrwwww____ddddeeeerrrreeeeffff____ccccoooommmmppppaaaarrrreeee<<<<EEEEQQQQ,,,,TTTT>>>> >>>> is the C++-standard collection that serves as the underlying implementation for RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>>. PPPPuuuubbbblllliiiicccc TTTTyyyyppppeeeeddddeeeeffffssss typedef rw_deref_compare<EQ,T> container_eq; typedef rw_deref_hash<H,T> container_hash; typedef rw_hashmultiset<T*,container_hash,container_eq> container_type; typedef container_type::size_type size_type; typedef container_type::difference_type difference_type; typedef container_type::iterator iterator; typedef container_type::const_iterator const_iterator; typedef T* value_type; typedef T* const& reference; typedef T* const& const_reference; PPPPaaaaggggeeee 2222 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (size_type sz=1024,const H& h = H(),const EQ& eq = EQ()); Constructs an empty multi set. The hash table representation used by self multi-set will have sssszzzz buckets, use hhhh as a hashing function and eeeeqqqq to test for equality between stored elements. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (const RWTPtrHashMultiSet<T,H,EQ>& rws); Copy constructor. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (const rw_hashmultiset<T*,container_hash, container_eq>& s); Constructs a hashed multi-set, copying all element from ssss. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (const H& h,size_type sz = RWDEFAULT_CAPACITY); This TTTToooooooollllssss....hhhh++++++++ 6.xstyle constructor creates an empty hashed multi-set which uses the hash object hhhh and has an initial hash table capacity of sssszzzz. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>>(T*const* first,T*const* last, size_type sz=1024,const H& h = H(),const EQ& eq = EQ()); Constructs a set by copying elements from the array of TTTT****s pointed to by ffffiiiirrrrsssstttt, up to, but not including, the element pointed to by llllaaaasssstttt. The hash table representation used by self multi-set will have sssszzzz buckets, use hhhh as a hashing function and eeeeqqqq to test for equality between stored elements. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss RWTPtrHashMultiSet<T,H,EQ>& ooooppppeeeerrrraaaattttoooorrrr====(const RWTPtrHashMultiSet<T,H,EQ>& s); Clears all elements of self and replaces them by copying all elements of ssss.... bool ooooppppeeeerrrraaaattttoooorrrr========(const RWTPtrHashMultiSet<T,H,EQ>& s) const; Returns ttttrrrruuuueeee if self compares equal to ssss, otherwise returns ffffaaaallllsssseeee. Two PPPPaaaaggggeeee 3333 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual elements that compare equal to each other. Elements are dereferenced before being compared. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaappppppppllllyyyy(void (*fn)(const T*,void*), void* d) const; Applies the user-defined function pointed to by ffffnnnn to every item in the collection. self function must have prototype: void yourfun(const T* a, void* d); Client data may be passed through parameter dddd. iterator bbbbeeeeggggiiiinnnn(); const_iterator bbbbeeeeggggiiiinnnn() const; Returns an iterator positioned at the first element of self. size_type ccccaaaappppaaaacccciiiittttyyyy() const; Returns the number of buckets(slots) available in the underlying hash representation. See rrrreeeessssiiiizzzzeeee below. void cccclllleeeeaaaarrrr(); Clears the collection by removing all items from self. void cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy(); Removes all items from the collection and uses ooooppppeeeerrrraaaattttoooorrrr ddddeeeelllleeeetttteeee to destroy the objects pointed to by those items. Do not use self method if multiple pointers to the same object are stored. PPPPaaaaggggeeee 4444 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) bool ccccoooonnnnttttaaaaiiiinnnnssss(const T* a) const; Returns ttttrrrruuuueeee if there exists an element tttt in self that compares equal to ****aaaa, otherwise returns ffffaaaallllsssseeee. bool ccccoooonnnnttttaaaaiiiinnnnssss(bool (*fn)(const T*,void*), void* d) const; Returns ttttrrrruuuueeee if there exists an element tttt in self such that the expression ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee, otherwise returns ffffaaaallllsssseeee. ffffnnnn points to a user-defined tester function which must have prototype: bbbboooooooollll yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr((((ccccoooonnnnsssstttt TTTT**** aaaa,,,, vvvvooooiiiidddd**** dddd))));;;; Client data may be passed through parameter dddd. void ddddiiiiffffffffeeeerrrreeeennnncccceeee(const RWTPtrHashMultiSet<T,H,EQ>& s); Sets self to the set-theoretic difference given by ((((sssseeeellllffff ---- ssss)))). Elements from each set are dereferenced before being compared. iterator eeeennnndddd(); const_iterator eeeennnndddd() const; Returns an iterator positioned "just past" the last element in self. size_type eeeennnnttttrrrriiiieeeessss() const; Returns the number of items in self. float ffffiiiillllllllRRRRaaaattttiiiioooo() const; Returns the ratio eeeennnnttttrrrriiiieeeessss(((())))/ccccaaaappppaaaacccciiiittttyyyy(((()))). PPPPaaaaggggeeee 5555 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) const T* ffffiiiinnnndddd(const T* a) const; If there exists an element tttt in self that compares equal to ****aaaa, returns tttt. Otherwise, returns rrrrwwwwnnnniiiillll. const T* ffffiiiinnnndddd(bool (*fn)(const T*,void*), void* d) const; If there exists an element tttt in self such that the expression ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee, returns tttt. Otherwise, returns rrrrwwwwnnnniiiillll. ffffnnnn points to a user-defined tester function which must have prototype: bbbboooooooollll yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr((((ccccoooonnnnsssstttt TTTT**** aaaa,,,, vvvvooooiiiidddd**** dddd))));;;; Client data may be passed through parameter dddd. bool iiiinnnnsssseeeerrrrtttt(T* a); Adds the item aaaa to the collection. Returns ttttrrrruuuueeee. void iiiinnnntttteeeerrrrsssseeeeccccttttiiiioooonnnn(const RWTPtrHashMultiSet<T,H,EQ>& s); Destructively performs a set theoretic intersection of self and ssss, replacing the contents of self with the result. bool iiiissssEEEEmmmmppppttttyyyy() const; Returns ttttrrrruuuueeee if there are no items in the collection, ffffaaaallllsssseeee otherwise. bool iiiissssEEEEqqqquuuuiiiivvvvaaaalllleeeennnntttt(const RWTPtrHashMultiSet<T,H,EQ>& s) const; Returns ttttrrrruuuueeee if there is set equivalence between self and ssss; returns ffffaaaallllsssseeee otherwise. bool iiiissssPPPPrrrrooooppppeeeerrrrSSSSuuuubbbbsssseeeettttOOOOffff(const RWTPtrHashMultiSet<T,H,EQ>& s) const; PPPPaaaaggggeeee 6666 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) Returns ttttrrrruuuueeee if self is a proper subset of ssss; returns ffffaaaallllsssseeee otherwise. bool iiiissssSSSSuuuubbbbsssseeeettttOOOOffff(const RWTPtrHashMultiSet<T,H,EQ>& s) const; Returns ttttrrrruuuueeee if self is a subset of ssss or if self is set equivalent to ssss, ffffaaaallllsssseeee otherwise. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const T* a) const; Returns the number of elements tttt in self that compare equal to ****aaaa. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(bool (*fn)(const T*,void*), void* d) const; Returns the number of elements tttt in self such that the expression((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const T* a, void* d); Client data may be passed through parameter dddd. T* rrrreeeemmmmoooovvvveeee(const T* a); Removes and returns the first element tttt in self that compares equal to ****aaaa. Returns rrrrwwwwnnnniiiillll if there is no such element. T* rrrreeeemmmmoooovvvveeee(bool (*fn)(const T*,void*), void* d); Removes and returns the first element tttt in self such that the expression ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee. Returns rrrrwwwwnnnniiiillll if there is no such element. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const T* a, void* d); PPPPaaaaggggeeee 7777 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) Client data may be passed through parameter dddd. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(const T* a); Removes all elements tttt in self that compare equal to ****aaaa. Returns the number of items removed. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(bool (*fn)(const T*,void*), void* d); Removes all elements tttt in self such that the expression ((((((((****ffffnnnn))))((((tttt,,,,dddd))))))))is ttttrrrruuuueeee. Returns the number of items removed. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const T* a, void* d); Client data may be passed through parameter dddd. void rrrreeeessssiiiizzzzeeee(size_type sz); Changes the capacity of self by creating a new hashed multi-set with a capacity of sssszzzz . rrrreeeessssiiiizzzzeeee copies every element of self into the new container and finally swaps the internal representation of the new container with the internal representation of sssseeeellllffff. rw_hashset<T*,container_hash,container_eq>& ssssttttdddd(); const rw_hashset<T*,container_hash,container_eq>& ssssttttdddd() const; Returns a reference to the underlying C++-standard collection that serves as the implementation for self. void ssssyyyymmmmmmmmeeeettttrrrriiiiccccDDDDiiiiffffffffeeeerrrreeeennnncccceeee(const RWTPtrHashMultiSet<T,H,EQ>& rhs); Destructively performs a set theoretic symmetric difference operation on self and rrrrhhhhssss. Self is replaced by the result. A symmetric difference can be informally defined as (A_B)-(A_B). PPPPaaaaggggeeee 8888 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiSSSSeeeetttt((((3333CCCC++++++++)))) void UUUUnnnniiiioooonnnn(const RWTPtrHashMultiSet<T,H,EQ>& rhs); Destructively performs a set theoretic union operation on self and rrrrhhhhssss. Self is replaced by the result. Note the uppercase "U" in UUUUnnnniiiioooonnnn to avoid conflict with the C++ reserved word. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTPtrHashMultiSet<T,H,EQ>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTPtrHashMultiSet<T,H,EQ>& coll); Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to it if it has already been saved. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrHashMultiSet<T,H,EQ>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrHashMultiSet<T,H,EQ>& coll); Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrHashMultiSet<T,H,EQ>*& p); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrHashMultiSet<T,H,EQ>*& p); Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a new collection off the heap and sets pppp to point to it, or sets pppp to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it. PPPPaaaaggggeeee 9999